#!/bin/bash
function checkIPv4Valid(){
    IP=$1
    if [[ ${IP} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        FIELD1=$(echo ${IP}|cut -d. -f1)
        FIELD2=$(echo ${IP}|cut -d. -f2)
        FIELD3=$(echo ${IP}|cut -d. -f3)
        FIELD4=$(echo ${IP}|cut -d. -f4)
        if [ ${FIELD1} -le 255 -a ${FIELD2} -le 255 -a ${FIELD3} -le 255 -a ${FIELD4} -le 255 ]; then
            return 0
        else
            echo "${IP} not a ipv4!"
            return 1
        fi
    else
        echo "${IP} not a ipv4!"
        return 1
    fi
}
checkIPv4Valid $1
if [ 0 -eq $? ];then
  sed -i "/^IPADDR=/cIPADDR=${1}" /etc/sysconfig/network-scripts/ifcfg-ens192
  sed -i "/^GATEWAY=/cGATEWAY=${1%\.*}.1" /etc/sysconfig/network-scripts/ifcfg-ens192
  systemctl restart network
  #nmcli c reload
  #nmcli up ens192
  systemctl stop firewalld
  systemctl disable firewalld
else 
 echo "ipv4 not valid!!"
fi
hostname ${1//\./-}
ip addr
